package timing.ukulele.flow.config;

import timing.ukulele.web.config.DefaultMvcConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;

@Configuration
public class BootMvcConfig extends DefaultMvcConfig {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        if (!debug) {
            registry.addViewController("/").setViewName("forward:/index.html");
            registry.addViewController("/page/**").setViewName("forward:/index.html");
            registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        }
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //父类方法中加入了swagger资源
        super.addResourceHandlers(registry);
        //系统前端静态页面配置（在不借助nginx等做反向代理的情况下可这么使用）
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/META-INF/webapp/static/");
        registry.addResourceHandler("index.html").addResourceLocations("classpath:/META-INF/webapp/");
        //文件上传所放置的路径加入到资源中
//        registry.addResourceHandler("/" + filePath + "**").addResourceLocations("file:" + deposePath);
    }
}
